<template>
  <div ref="containerRef" class="container"></div>
</template>
<script setup>
import { ref, onMounted, onBeforeUnmount } from "vue";
import { initEcharts, disposeEcharts } from "@/config/echartsUtil";

const containerRef = ref(null);
let myChart = null;
const init = () => {
  const option = {
    xAxis: {
      type: "category",
      data: ["Matcha Latte", "Milk Tea", "Cheese Cocoa", "Walnut Brownie"],
    },
    tooltip: {},
    yAxis: {},
    series: [
      {
        type: "bar",
        name: 2015,
        data: [89.3, 92.1, 94.4, 85.4],
        color: ["#91ca8c"],
      },
      {
        type: "bar",
        name: 2016,
        data: [89.3, 92.1, 94.4, 85.4],
        color: ["red"],
      },
      {
        type: "bar",
        name: 2017,
        data: [89.3, 92.1, 94.4, 85.4],
        colro: ["yellow"],
      },
    ],
  };
  myChart = initEcharts(containerRef.value, option);
};
onBeforeUnmount(() => {
  //   销毁实例;
  disposeEcharts(myChart);
});
onMounted(() => {
  init();
});
</script>
<style lang="less" scoped></style>
